@include('admin.layout.bone_header')

<div class="layui-form layui-form-pane search">

    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-inline">
            <input type="text" id="phone_like" autocomplete="off" placeholder="请输入手机号" class="layui-input">
        </div>
        <label class="layui-form-label">等级查询</label>
        <div class="layui-input-inline">
            <select id="user_level" lay-verify="">
                <option value="" selected>全部</option>
                <option value="0">普通</option>
                <option value="1">一星</option>
                <option value="2">二星</option>
                <option value="3">三星</option>
                <option value="4">四星</option>
                <option value="5">五星</option>
                <option value="6">六星</option>
                <option value="7">七星</option>
                <option value="8">八星</option>
                <option value="9">九星</option>
                <option value="10">十星</option>
                <option value="11">十一星</option>
                <option value="12">十二星</option>
                <option value="13">十三星</option>
            </select>
        </div>
        <label class="layui-form-label">有效用户</label>
        <div class="layui-input-inline">
            <select id="vip_index_level" lay-verify="">
                <option value="" selected>全部</option>
                <option value="0">否</option>
                <option value="1">是</option>
            </select>
        </div>




    </div>

    <div class="layui-form-item">

        <label class="layui-form-label">会员ID</label>
        <div class="layui-input-inline">
            <input type="text" id="user_id" autocomplete="off" placeholder="请输入会员ID" class="layui-input">
        </div>
        <label class="layui-form-label">邀请人ID</label>
        <div class="layui-input-inline">
            <input type="text" id="spread_id" autocomplete="off" placeholder="请输入邀请人ID" class="layui-input">
        </div>
        <label class="layui-form-label">开始时间</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" autocomplete="off" id="start_time" placeholder="开始时间" lay-key="1">
        </div>


    </div>
    <div class="layui-form-item">
    <label class="layui-form-label">结束时间</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" autocomplete="off" id="end_time" placeholder="结束时间" lay-key="2">
        </div>
    </div>
    <button class="layui-btn" data-type="reload">搜索</button>
</div>




<table class="layui-hide" id="think-table" lay-filter="think-table"></table>

<script type="text/html" id="barDemo">


        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="recharge">充值</a>
        <a class="layui-btn layui-btn-xs layui-btn-info" lay-event="recharge_score">充值金币</a>
        <a class="layui-btn layui-btn-xs layui-btn-success" lay-event="edit">编辑</a>


</script>

<script>

    layui.use(['table','laydate'], function () {
        let table = layui.table,
            laydate = layui.laydate;


        laydate.render({
            elem: '#start_time'
        });

        laydate.render({
            elem: '#end_time'
        });
        UI.getPageTable(table, "{{route('admin.users.users')}}", [
            {field: 'user_id', title: 'ID', width: 80, sort: true, fixed: 'left'}
            , {field: 'phone', width: 100, title: ' 手机号'}
            , {field: 'real_name', width: 100, title: ' 昵称'}
            , {field: 'score', width: 100, title: ' 金币'}
            , {field: 'balance', width: 100, title: ' 余额'}
            , {field: 'spread_id', width: 100, title: ' 上级用户ID'}
            , {field: 'user_level', width: 100, title: ' 会员等级',templet:function (d){
                let arr = ['普通','一星','二星','三星','四星','五星','六星','七星','八星','九星','十星','十一星','十二星','十三星']
                 return arr[d['vip_level']]
                }}
            , {field: 'vip_index_level', width: 100, title: ' 激活时间',templet:function (d){
                    if(d['activity_time'] == 0)
                        return '未激活';
                    return Utils.paraseTime(d['activity_time'])
                }}
            , {field: 'vip_index_level', width: 300, title: ' 注册时间',templet:function (d){
                    return Utils.paraseTime(d['created_at']);
                }}
            ,{fixed: 'right',width: 240,title:'操作', align:'center', toolbar: '#barDemo'}
        ]);

        table.on('tool(think-table)', function (obj) {
            let data = obj.data;
            if(obj.event === 'edit'){
                UI.openLayer('{{route('admin.users.edit')}}?user_id='+data['user_id']);
            }


            if(obj.event === 'recharge_score'){


                layer.prompt({formType:0,title:"充值",value:10000},
                    function(value, index){
                        HttpUtils.post('{{route('admin.users.recharge_score')}}',{
                            nums:value,
                            user_id:data['user_id']
                        },function (res){
                            if(res['code'] != 200){
                                Utils.errorToast(res['msg'])
                                return;
                            }
                            layer.close(index)
                            layui.table.reload("think-table");
                        });
                    });
            }
            if(obj.event === 'recharge') {
                layer.prompt({formType:0,title:"充值",value:10000},
                    function(value, index){
                        HttpUtils.post('{{route('admin.users.recharge')}}',{
                            money:value,
                            user_id:data['user_id']
                        },function (res){
                            if(res['code'] != 200){
                                Utils.errorToast(res['msg'])
                                return;
                            }
                            layer.close(index)
                            layui.table.reload("think-table");
                        });
                    });
            }
        });
        let $ = layui.$, active = {
            reload:function (){
                let user_id = $('#user_id');
                let phone_like = $('#phone_like');
                let user_level = $('#user_level');
                let vip_index_level = $('#vip_index_level');
                let spread_id = $('#spread_id');
                let start_time = $('#start_time');
                let end_time = $('#end_time');
                //执行重载
                table.reload('think-table', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        'user_id':user_id.val(),
                        'phone_like':phone_like.val(),
                        'vip_level':user_level.val(),
                        'vip_index_level':vip_index_level.val(),
                        'spread_id':spread_id.val(),
                        'start_time':start_time.val(),
                        'end_time':end_time.val(),
                    }
                });
            }
        };
        $('.layui-btn-container .layui-btn').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $('.search .layui-btn').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    })


</script>


@include('admin.layout.bone_footer')
